function [DFILE, err] = analysis_setup(DFILE, sf)
% general setup for analysis...
% 6/2/2002 P. Manis
%

global VOLTAGE CURRENT
global CONTROL

err = 1;
%-----------------------------General Setup--------------------------------
[DFILE1] = synch_file(DFILE, sf);
% do the "block info" thing to get stimulus parameters loaded into dfile.
%[sf, df] = block_info(DFILE1.fullfile, DFILE1.dblock);

if(isempty(DFILE1) | isempty(VOLTAGE))
   QueMessage('Analysis Setup: could not get DFILE');
   return;
end;
DFILE = DFILE1;

% verify fields in control structure. Create if they don't exist and then return.
update = 0; % flag
if(~check_field(CONTROL(sf),'stim_time')) % doesn't exist - then create it.
     CONTROL(sf).stim_time=[5 15 25 35 45];
%	disp('stim_time')
	update = 1;
end;
if(~check_field(CONTROL(sf),'psp_time'))
	CONTROL(sf).psp_time= [5.5 14 15.5 24 25.5 34 35.5 44 45.5 54];
%	disp('psp_time')
	update=1;
end
%if(~check_field(CONTROL(sf),'psp_reclist'))
%	CONTROL(sf).psp_reclist= ' ';
%	disp('reclist')
%	update=1;
%end
		 
% check for units and insert them if they are not present.
if(~check_field(CONTROL(sf), 'I_Unit') | isempty(CONTROL(sf).I_Unit))
   CONTROL(sf).I_Unit='pA';
end

if(~check_field(CONTROL(sf), 'V_Unit') | isempty(CONTROL(sf).V_Unit))
   CONTROL(sf).V_Unit='mV';
end  

if(~check_field(CONTROL(sf), 'T_Unit') | isempty(CONTROL(sf).T_Unit))
   CONTROL(sf).T_Unit='ms';
end
if(~isnumeric(CONTROL(sf).vgain)) | isempty(CONTROL(sf).vgain)
	CONTROL(sf).vgain = str2num(CONTROL(sf).vgain);
end;
if(~isnumeric(CONTROL(sf).igain) | isempty(CONTROL(sf).igain))
   CONTROL(sf).igain = str2num(CONTROL(sf).igain);
end;

if(~check_field(CONTROL(sf), 'sign_list') | isempty(CONTROL(sf).sign_list))
   CONTROL(sf).sign_list=[-1 -1];
end;

if(update==1)
%	QueMessage('Analysis setup: Updated Control with default psp params');
   err = 0;
   return;
end

err = 0;
return;

